import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { resolve } from "path";
import dts from "vite-plugin-dts";
import { visualizer } from "rollup-plugin-visualizer";

export default defineConfig({
  server: {
    host: "0.0.0.0",//ip地址
    port: 5177, // 设置服务启动端口号
    open: true // 设置服务启动时是否自动打开浏览器
  },
  build: {
    lib: {
      entry: resolve(__dirname, "./src/index.ts"),
      name: "react-antd-jssip",
      formats: ["es"],
      fileName: format => `index.${format}.js`
    },
    rollupOptions: {
      external: ["react", "react-dom"],
      output: {
        globals: {
          react: "React",
          "react-dom": "ReactDOM"
        }
      }
    }
  },
  plugins: [
    react(),
    visualizer({
      gzipSize: true,
      brotliSize: true,
      emitFile: false,
      filename: "test.html", //分析图生成的文件名
      open: true //如果存在本地服务端口，将在打包后自动展示
    }),
    dts({ rollupTypes: true, include: ["./src"], tsconfigPath: "./tsconfig.app.json" })
  ]
});
